package atguigu.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;


public class ParallelStreamDemo3 {
	public static void main(String[] args) {
        List<Integer>  list  =  new ArrayList<>();
        for (int j = 0; j < 1000; j++) {
            list.add(j);
        }
        System.out.println("最开始生成的集合长度:"+list.size());
        //parallelStream遍历数据的时候会产生丢失的问题
        for (int i = 0; i < 10 ; i++) {
            List<Integer> synchronizedList = new CopyOnWriteArrayList<Integer>();
            list.parallelStream().forEach(integer -> {
                synchronizedList.add(integer);
            });
            System.out.println("每次遍历的集合长度:"+ synchronizedList.size());
        }
    }
}
